package metronome;

import java.io.File;
import java.io.IOException;

import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
/**
 * Tuner for guitar strings.
 * @author Suwijak Suppapit 5510546204
 * @version 5/1/2013
 */
public class Tuner {
	private AudioInputStream audioE6;
	private Clip clipE6;
	private AudioInputStream audioA5;
	private Clip clipA5;
	private AudioInputStream audioD4;
	private Clip clipD4;
	private AudioInputStream audioG3;
	private Clip clipG3;
	private AudioInputStream audioB2;
	private Clip clipB2;
	private AudioInputStream audioE1;
	private Clip clipE1;

	/**
	 * Initialize Tuner.
	 */
	public Tuner() {
		try {
			audioE6 = AudioSystem.getAudioInputStream(this.getClass().getResource(
					"/sound/6th_String_E_64kb.wav"));
			clipE6 = AudioSystem.getClip();
			clipE6.open(audioE6);
		} catch (UnsupportedAudioFileException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (LineUnavailableException e) {
			e.printStackTrace();
		}
		
		try {
			audioA5 = AudioSystem.getAudioInputStream(this.getClass().getResource(
					"/sound/5th_String_A_64kb.wav"));
			clipA5 = AudioSystem.getClip();
			clipA5.open(audioA5);
		} catch (UnsupportedAudioFileException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (LineUnavailableException e) {
			e.printStackTrace();
		}
		
		try {
			audioD4 = AudioSystem.getAudioInputStream(this.getClass().getResource(
					"/sound/4th_String_D_64kb.wav"));
			clipD4 = AudioSystem.getClip();
			clipD4.open(audioD4);
		} catch (UnsupportedAudioFileException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (LineUnavailableException e) {
			e.printStackTrace();
		}
		try {
			audioG3 = AudioSystem.getAudioInputStream(this.getClass().getResource(
					"/sound/3rd_String_G_64kb.wav"));
			clipG3 = AudioSystem.getClip();
			clipG3.open(audioG3);
		} catch (UnsupportedAudioFileException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (LineUnavailableException e) {
			e.printStackTrace();
		}
		try {
			audioB2 = AudioSystem.getAudioInputStream(this.getClass().getResource(
					"/sound/2nd_String_B__64kb.wav"));
			clipB2 = AudioSystem.getClip();
			clipB2.open(audioB2);
		} catch (UnsupportedAudioFileException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (LineUnavailableException e) {
			e.printStackTrace();
		}
		try {
			audioE1 = AudioSystem.getAudioInputStream(this.getClass().getResource(
					"/sound/1st_String_E_64kb.wav"));
			clipE1 = AudioSystem.getClip();
			clipE1.open(audioE1);
		} catch (UnsupportedAudioFileException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} catch (LineUnavailableException e) {
			e.printStackTrace();
		}
		
	}

	/**
	 * Play the E-6 string sound.
	 */
	public void playE6() {
		clipE6.setFramePosition(0);
		clipE6.start();
	}
	/**
	 * Play the A-5 string sound.
	 */
	public void playA5() {
		clipA5.setFramePosition(0);
		clipA5.start();
	}
	/**
	 * Play the D-4 string sound.
	 */
	public void playD4() {
		clipD4.setFramePosition(0);
		clipD4.start();
	}
	/**
	 * Play the G-3 string sound.
	 */
	public void playG3() {
		clipG3.setFramePosition(0);
		clipG3.start();
	}
	/**
	 * Play the B-2 string sound.
	 */
	public void playB2() {
		clipB2.setFramePosition(0);
		clipB2.start();
	}
	/**
	 * Play the E-1 string sound.
	 */
	public void playE1() {
		clipE1.setFramePosition(0);
		clipE1.start();
	}
}
